package com.codeduck.test.quarzt;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import javax.annotation.Resource;

/**
 * @author: <a href="mailto:codeduck@163.com">codeduck</a>
 * @date: 2022/11/05
 */
@Component
@Slf4j
public class QuazrtJob {

    @Resource
    private Environment environment;

    @Value("${web.url-end-str}")
    private String urlEndStr;

    @Scheduled(cron = "0/5 * * * * ?")
    public void printConfigProperties() {
        String homeUrl = environment.getProperty("web.upload");
        log.info("webHome: [{}]", homeUrl);
    }

//    @Scheduled(cron = "0/10 * * * * ?")
    public void matchUrl() {
        String endStr = environment.getProperty("web.upload").substring(environment.getProperty("web.upload").lastIndexOf("/") + 1);
        if (endStr.endsWith(urlEndStr)) {
            log.info("upload url: [{}]", urlEndStr);
        }
    }
}
